#include "gameseting.h"
#include "ui_gameseting.h"
#include <QPainter>
#include <QListView>

GameSeting::GameSeting(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::GameSeting)
{
    ui->setupUi(this);
    setAttribute(Qt::WA_DeleteOnClose);//调用close时就调用析构，释放空间
    //    设置固定大小
    setFixedSize(470,720);
    //    设置标题
    setWindowTitle("CTYYPE");
    //    设置图标
    setWindowIcon(QIcon(":/image/enemy1.png"));
    //    设置按钮
    defaultBTN =new usualButton(this);
    defaultBTN->setText("系统默认");
    defaultBTN->move(60,400);
    selfBTN=new usualButton(this);
    selfBTN->setText("选择文件");
    selfBTN->move(291,400);
    startBTN = new picButton(0.3,":/image/gameStart.png");
    startBTN->move(177,480);
    startBTN->setParent(this);
    startBTN->setShadow();
    //选择词库
    connect(selfBTN,&usualButton::clicked,[=](){
       SelectFile_Info();

    });
    //系统默认
    connect(defaultBTN,&usualButton::clicked,[=](){
        ui->chooseLE->setText("选择词库（系统默认）");

    });
    //开始游戏
    connect(startBTN,&picButton::clicked,[=](){
        //           qDebug()<<"点击开始";
        startBTN->zoom1();
        startBTN->zoom2();
        if(ui->timeQCB->currentIndex()==0)
        {
            tgameTime=60000*1;
            newplaneTime=15;
        }
        else if(ui->timeQCB->currentIndex()==1)
        {
            tgameTime=60000*2;
            newplaneTime=12;
        }

        else if(ui->timeQCB->currentIndex()==2)
        {
            tgameTime=60000*3;
            newplaneTime=9;
        }

        else
        {
            newplaneTime=6;
            tgameTime=60000*5;
        }

        tMax_wrong=10-(ui->degreeQCB->currentIndex())*3;//10,7,4,1
        tplaneCount_time=0.05+(ui->degreeQCB->currentIndex())*0.05;//0.05,0.1,0.15,0.2
        game=new GameUI();
        QString judgess=ui->chooseLE->text();
        if(QString::compare(judgess,"选择词库（系统默认）")==0)
        {
            fileName=":/defaultText/test1.txt";
        }
//        qDebug()<<fileName;
        game->setParameter(tplaneCount_time,tgameTime,tMax_wrong, newplaneTime, fileName);
        game->show();
        this->close();
    });

    //    设置阴影
    QGraphicsDropShadowEffect *shadow_effect1 = new QGraphicsDropShadowEffect(this);
    shadow_effect1->setOffset(5, 5);
    shadow_effect1->setColor(QColor(43, 43, 43));
    shadow_effect1->setBlurRadius(8);
    ui->timeQCB->setGraphicsEffect(shadow_effect1);
    //ui->timeQCB->setView(new QListView());
    QGraphicsDropShadowEffect *shadow_effect2 = new QGraphicsDropShadowEffect(this);
    shadow_effect2->setOffset(5, 5);
    shadow_effect2->setColor(QColor(43, 43, 43));
    shadow_effect2->setBlurRadius(8);
    ui->degreeQCB->setGraphicsEffect(shadow_effect2);
    //ui->degreeQCB->setView(new QListView());
    QGraphicsDropShadowEffect *shadow_effect3 = new QGraphicsDropShadowEffect(this);
    shadow_effect3->setOffset(5, 5);
    shadow_effect3->setColor(QColor(43, 43, 43));
    shadow_effect3->setBlurRadius(8);
    ui->chooseLE->setGraphicsEffect(shadow_effect3);

    this->setStyleSheet("QLineEdit { background-color: #595959; border:3px solid #595959; color: #FBF8F3}"
                        "QComboBox { background-color: #FBF8F3;selection-background-color: #FBF8F3; selection-color: #595959; color: #595959}"
                        );
}

void GameSeting::paintEvent(QPaintEvent *event)
{
    QPainter resPainter(this);
    resPainter.drawPixmap(0,0,this->width(),this->height(),QPixmap(":/image/seting.jpg"));

}

void GameSeting::SelectFile_Info()
{
    fileName = QFileDialog::getOpenFileName(this,QStringLiteral("选择一个文件作为词库"),"D:",QStringLiteral("文本文件(*txt)"));
    ui->chooseLE->setText(fileName);
}

GameSeting::~GameSeting()
{
    delete defaultBTN;
    delete selfBTN;
    delete startBTN;
    delete ui;
}
